import { ref, onMounted } from "vue";
import { message } from "@/utils/message";
import { querySimulatorQuestionAllScore } from "@/api/simulatorexam";

export function useForm() {
  const scoreFormInline = ref({
    type0: 0,
    type1: 0,
    type2: 0,
    type3: 0
  });

  const score0 = ref(0);
  const score1 = ref(0);
  const score2 = ref(0);
  const score3 = ref(0);

  async function onQueryScore() {
    querySimulatorQuestionAllScore()
      .then(res => {
        if (res.success) {
          score0.value = res.score0;
          score1.value = res.score1;
          score2.value = res.score2;
          score3.value = res.score3;
        } else {
          message("查询数据异常:" + res.errMsg, { type: "error" });
        }
      })
      .catch(error => {
        message("查询数据异常:" + JSON.stringify(error), { type: "error" });
      });
  }

  onMounted(() => {
    onQueryScore();
  });

  return {
    scoreFormInline,
    score0,
    score1,
    score2,
    score3
  };
}
